<template>
  <ant-modal
    modalWidth="800"
    modalHeight="600"
    :visible="open"
    modal-title="设置生产工序"
    :adjust-size="true"
    @cancel="cancel"
  >
    <a-row slot="content">
      <advance-table
        tableKey="base-bizProductionProcess-index-table"
        @change="handleTableChange"
        rowKey="id"
        size="middle"
        @refresh="getList"
        :columns="columns"
        :data-source="bizProductionProcessList"
        :loading="loading"
        :format-conditions="true"
        :row-selection="{ selectedRowKeys: selectedRowKeys,onChange: onSelectChange }"
      >
      </advance-table>
    </a-row>
    <template slot="footer">
      <a-button :disabled="disabled" @click="cancel">
        取消
      </a-button>
      <a-button type="primary" :disabled="disabled" @click="confirm(true)">
        确定
      </a-button>
    </template>
  </ant-modal>
</template>
<script>
import {
  listAllBizProductionProcess
} from '@/api/biz/bizProductionProcess'
import {
  addBizProductProcessDetail
} from '@/api/biz/bizProductProcessDetail'
import AdvanceTable from '@/components/pt/table/AdvanceTable'
import AntModal from '@/components/pt/dialog/AntModal'
export default {
  name: 'BizProductProcess',
  components: {
    AdvanceTable,
    AntModal
  },
  data () {
    return {
      tempProcessPlanId:undefined,
      showAddModal: false,
      showEditModal: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 选中的主键集合
      selectedRowKeys: [],
      // 选中的数据集合
      selectedRows: [],
      // 高级搜索 展开/关闭
      advanced: false,
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // label的百分比
      labelCol: { span: 6 },
      // 内容区域的百分比
      wrapperCol: { span: 18 },
      // 生产工序表格数据
      bizProductionProcessList: [],
      // 查询参数
      queryParam: {
        processName: undefined,

        processCode: undefined

      },
      columns: [
        {
          title: '工序名称',
          dataIndex: 'processName',
          ellipsis: true,
          align: 'left',
          width: '20%'
        },
        {
          title: '工序编号',
          dataIndex: 'processCode',
          ellipsis: true,
          align: 'left',
          width: '20%'
        },
        {
          title: '部门',
          dataIndex: 'deptIdName',
          align: 'left',
          width: '12.8%'
        },
        {
          title: '准备工时',
          dataIndex: 'preparationHours',
          align: 'right',
          width: '12.8%'
        },
        {
          title: '标准工时',
          dataIndex: 'standardHours',
          align: 'right',
          width: '12.8%'
        },
        {
          title: '单位工资',
          dataIndex: 'unitSalary',
          align: 'right',
          width: '12.8%'
        }
      ],
      open: false,
      closeDialog: true,
      spinning: false,
      delayTime: 100,
      disabled: false,
      id: undefined
    }
  },
  created () {
  },
  methods: {
    /** 查询生产工序列表 */
    getList () {
      this.loading = true
      this.queryParam.excludeSelectedProcessIds=this.selectedProcessIds;
      listAllBizProductionProcess(this.queryParam).then(response => {
        this.bizProductionProcessList = response.data
        this.loading = false
      })
    },

    handleTableChange (pagination, filters, sorter) {
      if (sorter.field !== undefined && sorter.field !== null && sorter.field !== '') {
        this.queryParam.orderByColumn = 'a.' + sorter.field
        this.queryParam.isAsc = sorter.order
      }
      this.getList()
    },
    /** 修改按钮操作 */
    handleSetProcess (selectedProcessIds) {
      this.open = true;
      this.selectedProcessIds=selectedProcessIds;
      this.getList();
    },
    onSelectChange (selectedRowKeys, selectedRows) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRows = selectedRows
      this.ids = this.selectedRows.map(item => item.id)
      this.single = selectedRowKeys.length !== 1
      this.multiple = !selectedRowKeys.length
    },
    // 取消按钮
    cancel () {
      this.open = false
      this.$emit('close')
    },
    /** 提交按钮 */
    confirm: function (closeDialog) {
      // this.closeDialog = closeDialog
      this.disabled = true
      if(this.selectedRowKeys.length==0) {
        this.$message.warning('请选择生产工序');
        this.disabled = false
        return false
      } else {
        this.open = false
        this.$emit('ok',this.selectedRows);
        this.$emit('close')
        this.disabled = false
      }
    },
  }
}
</script>
